package com.suguowen.sblog.service;

import com.suguowen.sblog.bean.Comment;
import com.suguowen.sblog.bean.CommentExample;
import com.suguowen.sblog.bean.vo.CommonVO;
import com.suguowen.sblog.mapper.CommentMapper;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class DiscussionService {

    @Autowired
    CommentMapper commentMapper;

    // 展示评论
    public List<CommonVO> showCommon(Integer artId){
        return commentMapper.selectArtCommons(artId);
    }

    // 创建评论
    public void createComment(int articleId, Timestamp createTime, Integer senderId, Integer receiveId, String comment) {
        Comment commentBean = new Comment();
        commentBean.setArticleId(articleId);
        commentBean.setTime(createTime);
        commentBean.setContent(comment);
        commentBean.setUserId(senderId);
        commentBean.setFatherComment(receiveId);
        commentMapper.insertAutoId(commentBean);
    }

    public List<CommonVO> findNewestCommons() {
        return commentMapper.selectNewestCommons();
    }
}
